﻿using System;
using System.IO;
using System.Runtime.CompilerServices;

using Netbits.Common.Collections;

namespace Netbits.Common.Network
{
	public abstract class NetLinkSlot : IDisposable
	{
		#region Private Variables

		protected byte _Priority;
		protected NetLinkSession _Session;

		bool _Disposed;
		LockedList<NetLinkSlotSendItem> _SendQueue;

		#endregion

		#region Constructor

		public NetLinkSlot( NetLinkSession Session_, byte Priority_ )
		{
			_Priority = Priority_;
			_Session = Session_;

			_SendQueue = new LockedList<NetLinkSlotSendItem>();
		}

		#endregion

		#region Public Properties

		public byte Priority
		{
			get { return _Priority; }
		}

		#endregion

		#region Public Functions

		public NetLinkSlotSendItem Send( Stream Data_, int Position_, int Size_ )
		{
			NetLinkSlotSendItem nlssi = new NetLinkSlotSendItem( Data_, Position_, Size_ );

		}

		public void Send( byte[] Data_, int IndexOf_, int Size_ )
		{
			NetLinkSlotSendItem nlssi = null;
			try
			{
				nlssi = Send( Data_, IndexOf_, Size_, true );
				nlssi.WaitSendFinished();
			}
			finally
			{
				if( nlssi != null )
					nlssi.Dispose();
			}
		}

		public NetLinkSlotSendItem Send( byte[] Data_, int IndexOf_, int Size_, bool Wait_ )
		{
		}

		#endregion

		#region Internal Functions

		internal void HandleData( byte[] Data_, int Size_ )
		{
		}

		protected virtual void __HandleData( byte[] Data_, int Size_ )
		{
		}

		#endregion

		#region IDisposable

		public void Dispose()
		{
			if( !_Disposed )
			{

				_Disposed = true;
			}
		}

		#endregion
	}
}
